package com.alcj.controller;

import com.alcj.common.constant.SysConstant;
import com.alcj.common.utils.CmnUtil;
import com.alcj.model.ContactUs;
import com.alcj.model.FirmCulture;
import com.alcj.model.User;
import com.alcj.service.CompanyAboutService;
import com.alcj.service.UserService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author :chenxh
 * @version :v1.0
 * @Package :com.alcj.controller
 * @Description :${TODO}(企业关于业务逻辑)
 * @date :
 */
@Controller
@RequestMapping("/about")
public class CompanyAboutController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    CompanyAboutService companyAboutService;

    /**
     * @Author: chenxh
     * @Description:
     * @Date: 2017/9/7 16:13
     * @param: request
     * @param: model
     */
    @RequestMapping("/publicizeFront")
    public String publicizeInitFront(HttpServletRequest request, Model model) {
        try {

            // 设定检索条件
            List<FirmCulture> resultInfo = companyAboutService.getFrontInfo();

            // 初期设定信息
            if (!CmnUtil.isEmpty(resultInfo)) {
                model.addAttribute("data", resultInfo);
            } else {
                model.addAttribute("data", null);
            }

        } catch (Exception e) {
            // 异常报错
            logger.error("获取宣传信息异常 : {}", e.getMessage());
            logger.error("异常详细信息 :",e);
            return SysConstant.ERROR_PAGE_500;
        }

        return "publicizeFront";
    }

    /**
     * @Author: chenxh
     * @Description:
     * @Date: 2017/9/7 16:13
     * @param: request
     * @param: model
     */
    @RequestMapping("/publicizeRear")
    public String publicizeInitRear(HttpServletRequest request, Model model) {
        try {

            // 设定检索条件
            List<FirmCulture> resultInfo = companyAboutService.getRearInfo();

            // 初期设定信息
            if (!CmnUtil.isEmpty(resultInfo)) {
                model.addAttribute("data", resultInfo);
            } else {
                model.addAttribute("data", null);
            }

        } catch (Exception e) {
            // 异常报错
            logger.error("获取后台宣传信息异常 : {}", e.getMessage());
            logger.error("异常详细信息 :",e);
            return SysConstant.ERROR_PAGE_500;
        }

        return "publicizeRear";
    }

    /**
     * @Author: chenxh
     * @Description:
     * @Date: 2017/9/7 16:13
     * @param: request
     * @param: model
     */
    @RequestMapping("/contactUs")
    public String getContactUsInfo(HttpServletRequest request, Model model) {
        try {

            // 设定检索条件
            List<ContactUs> resultInfo = companyAboutService.getContactUsInfo();

            // 初期设定信息
            if (!CmnUtil.isEmpty(resultInfo)) {
                model.addAttribute("data", resultInfo);
            } else {
                model.addAttribute("data", null);
            }

        } catch (Exception e) {
            // 异常报错
            logger.error("获取联系我们信息异常 : {}", e.getMessage());
            logger.error("异常详细信息 :",e);
            return SysConstant.ERROR_PAGE_500;
        }

        return "publicizeFront";
    }
}
